﻿using System;

namespace Ping.Core
{
	/// <summary>
	/// The interface for a channel that sends & receives data-packets.
	/// </summary>
	public interface IChannel
	{
		/// <summary>
		/// Whether or not the channel is currently connected to an endpoint.
		/// </summary>
		bool IsConnected { get; }

		void Disconnect();

		/// <summary>
		/// Begins sending the given data.
		/// The callback is invoked as soon as the data has been sent or when an error occured.
		/// </summary>
		/// <param name="data"></param>
		/// <param name="userData"></param>
		/// <param name="callback"></param>
		/// <returns></returns>
		IAsyncResult BeginSend(Data data, object userData, AsyncCallback callback);

		/// <summary>
		/// Ends an asynchronous send operation.
		/// </summary>
		/// <param name="result"></param>
		void EndSend(IAsyncResult result);


		/// <summary>
		/// Begins receiving a data-packet.
		/// </summary>
		/// <param name="userData"></param>
		/// <param name="callback"></param>
		/// <returns></returns>
		IAsyncResult BeginReceive(object userData, AsyncCallback callback);

		/// <summary>
		/// Ends receiving a data-packet.
		/// </summary>
		/// <param name="result"></param>
		/// <returns></returns>
		Data EndReceive(IAsyncResult result);
	}
}